package com.aihome.springbootmybatisplus.utils;

import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.ITypeConvert;
import com.baomidou.mybatisplus.generator.config.converts.MySqlTypeConvert;
import com.baomidou.mybatisplus.generator.config.rules.DbColumnType;
import com.baomidou.mybatisplus.generator.config.rules.IColumnType;

/**
 * @author zhangjigang
 * @ClassName MyJavaTypeResolver
 * @Description java类型转换器
 * @Date 17:46 2020/4/1
 **/
public class MyJavaTypeResolver extends MySqlTypeConvert implements ITypeConvert {

    /**
     * 将tinyint转换为Integer，这里是关键所在
     */
    @Override
    public IColumnType processTypeConvert(GlobalConfig globalConfig, String fieldType) {
        String t = fieldType.toLowerCase();
        if (t.contains("tinyint")) {
            return DbColumnType.INTEGER;
        }
        return super.processTypeConvert(globalConfig, fieldType);
    }
}
